package com.xuhuan.client.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;

import java.util.Arrays;

/**
 * @Author huan.xu
 * @Date 2023/6/17 20:32
 * @Description StopWatch工具类
 */
@Slf4j
public class StopWatchUtil {

    private StopWatchUtil() {
    }

    /**
     * 打印printlnStopWatch信息
     * @param stopWatch
     */
    public static void printlnStopWatch(StopWatch stopWatch) {
        StopWatch.TaskInfo[] taskInfo = stopWatch.getTaskInfo();
        Arrays.stream(taskInfo).forEach(info -> {
            log.info("步骤[{}]耗时[{}]毫秒", info.getTaskName(), info.getTimeMillis());
        });
    }
}
